window.onload = function () {
  const btn = document.querySelector('button')
  const username = document.querySelector('.username')
  const password = document.querySelector('.password')

  btn.addEventListener('click', () => {

    if (!username.value || !password.value) {
      popup.msg('账号和密码不可以为空！')
      return
    }
    let reg = /^[a-zA-Z0-9_]{4,10}$/
    if (!reg.test(username.value)) {
      popup.msg('用户名数字/字母/下划线4-10位！')
      return
    }
    if (username.value !== 'admin' || password.value !== '123456') {
      popup.msg('用户名或者密码错误！')
      return
    }
    setCookie('username', username.value, 7200)
    request({
      method: 'post',
      url: '/login',
      data: {
        username: username.value,
        password: password.value,
      },

    }).then(res => {
      console.log(res)
      if(res.error_code === 200){
          location.href = '../index.html'
      }
    })
  })

}

